<template>
	<view class="container">
		<uni-list v-for="item, index in classmateList" :key="index">
			<uni-list-chat :avatar-circle="true" :avatar="item.headicon" :title="item.name" :note="item.department"
				:show-badge="true" :badge-text="item.unread" badgeType="error" @click="toDetails(item.id)" link>
			</uni-list-chat>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				classmateList: [],
				extra: [{
						headicon: "/static/head_icon.png",
						unread: 6
					},
					{
						headicon: "/static/logo.png",
						unread: 7
					}
				]
			}
		},
		methods: {
			toDetails(id) {
				uni.navigateTo({
					url: '/pages/cmdetails/cmdetails?id=' + id
				});
			},
			getDate() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/list',
					method: 'POST',
					success: res => {
						if (res.data.success) {
							this.classmateList = res.data.list.map((item, index) => {
								return {
									...item,
									...this.extra[index]
								};
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getCloudData(){
				uniCloud.callFunction({
					name:"usercf",
				}).then((res)=>{
					console.log(res.result.data);
					this.classmateList=res.result.data
				})
			}
		},
		onLoad() {
			// this.getDate()
			this.getCloudData()
		},
		onPullDownRefresh() {
			this.classmateList = []
			// this.getDate()
			this.getCloudData()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		}
	}
</script>

<style>

</style>